package exception;

public class Person1 {
    private int age ;
    public int getAge(){
        return age;
    }
    public void setAge(int age) throws IllegalAgeException {
        if(age<0||age>100) {
            //throw 将异常实例抛出到setAge方法之外。
            throw new IllegalAgeException("年龄不合法");
        }
        this.age = age;
    }
}
